package com.yh.homestay.controller;

import com.yh.homestay.aop.SystemLog;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.pojo.SysOrder;
import com.yh.homestay.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @ClassName OrderController
 * @Description 订单controller
 * @Date 2020/1/2 10:32
 */
@RestController
@Api(description = "订单管理")
@RequestMapping(value = "/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * @param page
     * @param limit
     * @param orderType
     * @param orderPayType
     * @param orderId
     * @Date: 2020/1/13 16:25
     * @Description: TODO
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @SystemLog(methods = "订单列表", module = "订单管理")
    @ApiOperation(value = "获取所有订单列表", notes = "获取所有订单信息或者模糊查询")
    public HomeStayResult findCapitalItemAll(Integer page, Integer limit, Integer orderType, Integer orderPayType, Long orderId) {
        return orderService.findAllOrder(page, limit, orderType, orderPayType, orderId);
    }

    /**
     * @param roomType
     * @param orderPick
     * @param orderPayType
     * @param orderDesc
     * @Date: 2020/1/14 19:29
     * @Description: 添加订单信息
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping("/add")
    @SystemLog(methods = "添加订单", module = "订单管理")
    @ApiOperation(value = "添加订单", notes = "添加订单")
    public HomeStayResult addOrder(Integer roomType, Integer orderPick, Integer orderPayType, String orderDesc) {
        //补全订单属性
        SysOrder order = new SysOrder();
        order.setUserId(2);
        order.setOrderDesc(orderDesc);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c = Calendar.getInstance();
        Date begin = c.getTime();
        order.setOrderCreateTime(begin);
        c.add(Calendar.DATE, +1);
        Date time = c.getTime();
        order.setOrderEndTime(time);
        order.setOrderType(3);
        order.setOrderItemId(14);
        order.setOrderRoomId(13);
        order.setOrderPayType(orderPayType);
        order.setOrderPick(orderPick);
        return orderService.addOrder(order, time);
    }

}
